﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WebBase;
using Newtonsoft.Json;
namespace PlaceApi
{
    public class PlaceAPI
    {
        public string key = "";
        public string baseUrl = "http://api.map.baidu.com/place/search";
        public string output = "json";
        public PlaceAPI(string key)
        {
            this.key = key;
        }
        /// <summary>
        ///{
        ///    "status":"OK",
        ///    "results":[
        ///        {
        ///            "name":"中国进出口银行(北京分行)",
        ///            "location":{
        ///                "lat":39.934788,
        ///                "lng":116.412264
        ///            },
        ///            "address":"东城区北河沿大街77号",
        ///            "uid":"66363382476cd764ca1b9542",
        ///            "tag":"其他",
        ///            "detail_url":"http://api.map.baidu.com/place/detail?uid=66363382476cd764ca1b9542&output=html&source=placeapi"
        ///        },
        ///    ]
        ///}
        /// </summary>
        /// <param name="region"></param>
        /// <returns></returns>
        public dynamic GetResponse(string query, string region)
        {
            var url = ReqHelper.BuildUrl(baseUrl,
                Tuple.Create("query", query),
                Tuple.Create("region", region),
                Tuple.Create("output", output),
                Tuple.Create("key", key));
            var ret = ReqHelper.ReqGET(url);
            return JsonConvert.DeserializeObject(ret);
        }
    }
}
